package com.machine.filling.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.machine.filling.R;


/**
 * 作者: SageTripp
 * 时间: 2018/1/16
 * <p>
 * 描述:确认的提示框
 */
public class ProgressDialog extends Dialog {

    /**
     * 确认消息
     */
    private String mProgressMessage = "";
    private boolean showProgress = true;
    private OnCancelListener onCancelListener;
    private TextView tv_text;


    private ProgressDialog(@NonNull Context context) {
        super(context, R.style.TransparentDialog);
    }

    /**
     * @param progressMessage 确认提示信息
     * @return 确认的提示框
     */
    public static ProgressDialog create(Context context ,@NonNull String progressMessage) {
        ProgressDialog dialog = new ProgressDialog(context);
//        dialog.setTitle(title);
        dialog.setProgressMessage(progressMessage);
        return dialog;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_progress);
        initView();
    }

    private void initView() {

        ProgressBar progressBar = (ProgressBar) findViewById(R.id.progress);
        progressBar.setVisibility(showProgress ? View.VISIBLE : View.GONE);

        tv_text = (TextView) findViewById(R.id.tv_text);
        tv_text.setText(mProgressMessage);
        setCancelable(false);
        setCanceledOnTouchOutside(false);
    }

    /**
     * 获取确认提示信息
     *
     * @return 确认提示信息
     */
    @NonNull
    public String getProgressMessage() {
        return mProgressMessage;
    }

    /**
     * 设置确认提示信息
     *
     * @param progressMessage 确认提示信息
     */
    public ProgressDialog setProgressMessage(@NonNull String progressMessage) {
        this.mProgressMessage = progressMessage;
        if (null != tv_text)
            tv_text.setText(mProgressMessage);
        return this;
    }

    public ProgressDialog showProgress(boolean showProgress) {
        this.showProgress = showProgress;
        return this;
    }

    /**
     * 取消
     */
    public void cancel() {
        mProgressMessage = "";
        dismiss();
    }

}
